package com.manager.core.web.exception;

import com.manager.commons.log.LogFactory;
import com.manager.core.web.json.AjaxJson;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class ExceptionAdvice {

    protected static final Logger logger = LogFactory.getLogger(ExceptionAdvice.class);

    @ExceptionHandler//这个注解也可以指定捕获的异常类型
    public AjaxJson handler(Exception e) {//也可以接收具体的异常
        logger.error("发生异常，e:", e);
        //如果代码出现Exception异常(包括Exception的⼦类),就返回⼀个Result的对象
        return new AjaxJson(-2, "网络异常，请稍后再试！");
    }
}
